package com.hsxc.cdz.monitor.bean.server.v1_21;

import com.hsxc.cdz.base.util.BytesUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ReferenceCountUtil;

/**
 * 
 * @author 刘力文 服务器下发充电桩开始充电的报文类
 */
public class ChargeSerMsg extends ServerMessage {
	public static int length = 20;// 交流桩报文长度
	private int chargePort; // 充电口号 0 表示 A口，1表示B口
	private int controll; // 开机限制数据
	private int limitData; // 开机限制数据
	private String startTime;// 定时启动
	private String CardNum; // 用户卡号

	public int getChargePort() {
		return chargePort;
	}

	public void setChargePort(int chargePort) {
		this.chargePort = chargePort;
	}

	public int getControll() {
		return controll;
	}

	public void setControll(int controll) {
		this.controll = controll;
	}

	public int getLimitData() {
		return limitData;
	}

	public void setLimitData(int limitData) {
		this.limitData = limitData;
	}

	public String getCardNum() {
		return CardNum;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public void setCardNum(String cardNum) {
		CardNum = cardNum;
	}

	@Override
	public byte[] getBytesFromMessage() {
		ByteBuf bytes = Unpooled.buffer(length);
		byte[] result;
		byte[] temp;
		
		temp  = BytesUtil.intToBytesSeq(this.getChargePort(), 1);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.intToBytesSeq(this.getControll(), 1);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.intToBytesDesc(this.getLimitData(), 4);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.strToBcdBytes(this.getStartTime(), 4);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.strToBcdBytes(this.getCardNum(), 10);
		bytes.writeBytes(temp);
		result = new byte[bytes.readableBytes()];
		bytes.readBytes(result);
		ReferenceCountUtil.release(bytes);
		return result;
	}

}
